package LeetCode;

import Constructs.TreeNode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/31.
//
//https://leetcode.cn/problems/same-tree/description/
public class 相同的树 {
    public static void main(String[] args) {
        System.out.println();

    }
    public static boolean isSameTree(TreeNode p, TreeNode q) {
        boolean[] flag = new boolean[1];
        flag[0] = true;
        isSameTreeFunction(p,q,flag);
        return flag[0];
    }

    private static void isSameTreeFunction(TreeNode p, TreeNode q, boolean[] flag) {
        if(p == null && q == null){
            return;
        }else if(p == null || q == null){
            flag[0] = false;
            return;
        }
        if(p.left != null && q.left != null){
            isSameTreeFunction(p.left,q.left,flag);
        }else if(p.left != null || q.left != null){
            flag[0] = false;
            return;
        }
        if(p.val != q.val){
            flag[0] = false;
            return;
        }
        if(p.right != null && q.right != null){
            isSameTreeFunction(p.right,q.right,flag);
        }else if(p.right != null || q.right != null){
            flag[0] = false;
        }
    }

}
